import os

import requests
from openpyxl.reader.excel import load_workbook

file_dir = r'D:\Desktop\exceltest\新导入部门'
saveurl = ''
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36',
    'Cookie':'JSESSIONID=4da18720-b0df-49d2-8453-9da842e7f52d; James_cookie_sYQDUGqqzHtheme=custom'
}

all_files = os.listdir(file_dir)
xlsx_files = list(filter(lambda name: name.endswith('.xlsx'),all_files))

for file_name in xlsx_files:
    file_param = file_name.split('.')[0].split('--')
    source_wb = load_workbook(fr'{file_dir}\{file_name}')
    source_ws = source_wb['批量导入机构模板']
    source_num = 3
    cell_A = source_ws[f'A{source_num}'].value
    cell_B = source_ws[f'B{source_num}'].value
    cell_C = source_ws[f'C{source_num}'].value
    cell_D = source_ws[f'D{source_num}'].value
    cell_E = source_ws[f'E{source_num}'].value
    while cell_A is not None:
        param = {}
        param['csrf'] = 'c93a265b728b4bafb20f864b87ea6e39'
        param['organ_level'] = '3' if file_param[3].startswith('5300') else '4'
        param['parent_type'] = 'organ'
        param['type'] = '0'
        param['tyshxydm'] = cell_B
        param['code'] = cell_A
        param['short_code'] = cell_C
        param['name'] = cell_D
        param['short_name'] = cell_E
        param['organ_type'] = '9FB587BCDAA74286B7AD60567B26F79A'
        param['region_code'] = file_param[3]
        param['region_name'] = file_param[2]
        param['parent_code'] = file_param[1]
        param['path_parent_code'] = ''
        param['parent_name'] = file_param[0]
        param['sort_order'] = '1'
        param['leader'] = ''
        param['phone'] = ''
        param['email'] = ''
        param['zip_code'] = ''
        param['is_law'] = '0'
        param['is_hall'] = '0'
        param['is_monitor'] = '0'
        param['is_risk'] = '0'
        param['is_center'] = '0'
        param['win_num'] = '0'
        param['address'] = ''
        param['page_home'] = ''
        param['industry'] = '1'
        param['industry_name'] = '政府'
        param['gmorg_code'] = ''
        param['remark'] = ''
        # response = requests.post(url=saveurl, headers=headers, data=param)
        # print(response.text)
        print(param)
        source_num += 1
        cell_A = source_ws[f'A{source_num}'].value
        cell_B = source_ws[f'B{source_num}'].value
        cell_C = source_ws[f'C{source_num}'].value
        cell_D = source_ws[f'D{source_num}'].value
        cell_E = source_ws[f'E{source_num}'].value



